how do I execute a command that is currently of type string

Please can anyone advise whether it is possible to create string array, and then convert each array item to run as an executable command.

For example:

myStringArrary = {"print "Press 1"", "print "Press 2""}

What DXL command can I use to access the array items and to get the DXL to excute the 2 print commands?

Thanks for any help on this
monde888 - Mon Apr 26 13:06:19 EDT 2010

Re: how do I execute a command that is currently of type string
llandale - Mon Apr 26 17:25:11 EDT 2010

You can use 'eval_' to execute a script, that can of course be only a single line. The interface is purely 'string' so you cannot send anything like an Object handle to eval_. eval_ can return a string value back to the calling program via the 'return_(string)' function; which stores the returned string until eval_ finishes naturally.

So in your case:

string myStringArrary[] = {"print \"Press 1\\n\"", "print \"Press 2\\n\""} 
int    i
for (i=0; i<sizeof(myStringArrary); i++) 
   eval_(myStringArrary[i])

 

  • Louie


If you must send handles on real things, you can for example send the full path of the current module and also the current object identifier, and the eval_ string can open the module and find the Object, and then do its work.

 

Re: how do I execute a command that is currently of type string
monde888 - Mon May 10 05:55:54 EDT 2010

llandale - Mon Apr 26 17:25:11 EDT 2010

You can use 'eval_' to execute a script, that can of course be only a single line. The interface is purely 'string' so you cannot send anything like an Object handle to eval_. eval_ can return a string value back to the calling program via the 'return_(string)' function; which stores the returned string until eval_ finishes naturally.

So in your case:

string myStringArrary[] = {"print \"Press 1\\n\"", "print \"Press 2\\n\""} 
int    i
for (i=0; i<sizeof(myStringArrary); i++) 
   eval_(myStringArrary[i])

 

  • Louie


If you must send handles on real things, you can for example send the full path of the current module and also the current object identifier, and the eval_ string can open the module and find the Object, and then do its work.

 

Thank you for your quick reply.
That worked !!
I don't suppose you know of a solution for a similar problem do you:

I have defined a series of filters (filter1, filter2, filter3...)
I need to run each of these filters in turn.

Would it be possible to create a string array with items:

{"set filter1", "set filter2", "set filter3}

Is there anyway that I would be able execute these array items as a command? If not, do you know of another solution to my problem?

Thanks in advance

Re: how do I execute a command that is currently of type string
llandale - Mon May 10 12:24:04 EDT 2010

monde888 - Mon May 10 05:55:54 EDT 2010
Thank you for your quick reply.
That worked !!
I don't suppose you know of a solution for a similar problem do you:

I have defined a series of filters (filter1, filter2, filter3...)
I need to run each of these filters in turn.

Would it be possible to create a string array with items:

{"set filter1", "set filter2", "set filter3}

Is there anyway that I would be able execute these array items as a command? If not, do you know of another solution to my problem?

Thanks in advance

I think you are asking: get several filters ready, and offer the user to select one and then another, and apply each on demand from the user.

Well, you would not really HAVE to get each filter ready in advance; each button could realistically calculate and apply the filter. Anyway, perhaps the following will get you started.
 

DB    dbFilt
DBE     dbeFilts
 
void    CalculateFilters()
{
        Filter  flt = null
 
        //calculate flt for c_FiltLabels[0]
        put(g_skpFilters, c_FiltLabels[0], flt)
 
        //calculate flt for c_FiltLabels[1]
        put(g_skpFilters, c_FiltLabels[1], flt)
 
        //calculate flt for c_FiltLabels[2]
        put(g_skpFilters, c_FiltLabels[2], flt)
}
 
void    clbkFilts(DBE dbeXX)
{     // Callback fires when user selects a Filter
 
        int     iFilt   = get(dbeFilts)
        string  Label
        Filter  flt
        if (iFilt < 0) return         // this is impossible
        Label   = c_FiltLabels[iFilt]
        infoBox("Dealing with filter '" Label "'")
        find(g_skpFilters,Label, flt)
 
        // now apply flt to the module
}
 
void    applyClose(DB dbXX)
{     delete(g_skpFilters)
        hide(dbFilt)
        destroy(dbFilt)
}
 
void    MakeDialog()
{
        g_skpFilters    = createString()
        CalculateFilters()
        dbFilt          = create("Choose Filters")
        dbeFilts        = verticalRadioBox(dbFilt, "Filters", c_FiltLabels, -1)
        set(dbeFilts, clbkFilts)        // Callback fires when user selects filter
        close(dbFilt, true, applyClose)
 
        realize(dbFilt)
        show(dbFilt)
}
 
MakeDialog()

 

  • Louie

 

Re: Oops, full DXL
llandale - Mon May 10 13:37:14 EDT 2010

llandale - Mon May 10 12:24:04 EDT 2010

I think you are asking: get several filters ready, and offer the user to select one and then another, and apply each on demand from the user.

Well, you would not really HAVE to get each filter ready in advance; each button could realistically calculate and apply the filter. Anyway, perhaps the following will get you started.
 

DB    dbFilt
DBE     dbeFilts
 
void    CalculateFilters()
{
        Filter  flt = null
 
        //calculate flt for c_FiltLabels[0]
        put(g_skpFilters, c_FiltLabels[0], flt)
 
        //calculate flt for c_FiltLabels[1]
        put(g_skpFilters, c_FiltLabels[1], flt)
 
        //calculate flt for c_FiltLabels[2]
        put(g_skpFilters, c_FiltLabels[2], flt)
}
 
void    clbkFilts(DBE dbeXX)
{     // Callback fires when user selects a Filter
 
        int     iFilt   = get(dbeFilts)
        string  Label
        Filter  flt
        if (iFilt < 0) return         // this is impossible
        Label   = c_FiltLabels[iFilt]
        infoBox("Dealing with filter '" Label "'")
        find(g_skpFilters,Label, flt)
 
        // now apply flt to the module
}
 
void    applyClose(DB dbXX)
{     delete(g_skpFilters)
        hide(dbFilt)
        destroy(dbFilt)
}
 
void    MakeDialog()
{
        g_skpFilters    = createString()
        CalculateFilters()
        dbFilt          = create("Choose Filters")
        dbeFilts        = verticalRadioBox(dbFilt, "Filters", c_FiltLabels, -1)
        set(dbeFilts, clbkFilts)        // Callback fires when user selects filter
        close(dbFilt, true, applyClose)
 
        realize(dbFilt)
        show(dbFilt)
}
 
MakeDialog()

 

  • Louie

 

Oops. Snipped off the top of the DXL.

Skip  g_skpFilters    //KEY: 'string' Label of Filter; DATA: 'Filter'
 
string    c_FiltLabels[] = {
                        "Filter 1",
                        "Filter 2",
                        "Filter 3"
                        }
 
DB      dbFilt
DBE     dbeFilts
 
void    CalculateFilters()
{
        Filter  flt = null
 
        //calculate flt for c_FiltLabels[0]
        put(g_skpFilters, c_FiltLabels[0], flt)
 
        //calculate flt for c_FiltLabels[1]
        put(g_skpFilters, c_FiltLabels[1], flt)
 
        //calculate flt for c_FiltLabels[2]
        put(g_skpFilters, c_FiltLabels[2], flt)
}
 
 
void    clbkFilts(DBE dbeXX)
{     // Callback fires when user selects a Filter
 
        int     iFilt   = get(dbeFilts)
        string  Label
        Filter  flt
        if (iFilt < 0) return         // this is impossible
        Label   = c_FiltLabels[iFilt]
        infoBox("Dealing with filter '" Label "'")
        find(g_skpFilters,Label, flt)
 
 
        // now apply flt to the module
}
 
void    applyClose(DB dbXX)
{     delete(g_skpFilters)
        hide(dbFilt)
        destroy(dbFilt)
}
 
void    MakeDialog()
{
        g_skpFilters    = createString()
        CalculateFilters()
        dbFilt  = create("Choose Filters")
        dbeFilts        = verticalRadioBox(dbFilt, "Filters", c_FiltLabels, -1)
        set(dbeFilts, clbkFilts)        // Callback fires when user selects filter
        close(dbFilt, true, applyClose)
 
        realize(dbFilt)
        show(dbFilt)
}
 
MakeDialog()